<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <input type="text" id="txt">
    <button id="btn">btn</button>
    <script>
        /*
        量词：规定字符出现的次数
        */
        var txt=document.getElementById("txt");
        var btn=document.getElementById("btn");
        var reg=/^\d{6}$/;
            btn.onclick=function(){
                var value=txt.value;
                var result=reg.test(value);
                console.log(result);
            //    if(result){
            //        alert("输入正确")
            //    }else{
            //     alert("只能输入6位数字")
            //    }
            }
    </script>
</body>
</html>